package com.nali.dal.mongo.dao;

import com.mongodb.DB;
import com.nali.dal.dao.IQueryDao;
import com.nali.dal.dao.IQueryDaoFactory;
import com.nali.dal.ds.IDataSource;
import com.nali.dal.ds.UsingDataSource;

public class MongoQueryDaoFactory implements IQueryDaoFactory, UsingDataSource<DB> {
	private DB db;

	public MongoQueryDaoFactory() {
		super();
	}

	public MongoQueryDaoFactory(IDataSource<DB> ds) {
		this(ds.getConnection());
	}

	public MongoQueryDaoFactory(DB db) {
		super();
		this.db = db;
	}

	@Override
	public void setDataSource(IDataSource<DB> ds) {
		this.db = ds.getConnection();		
	}

	@Override
	public IQueryDao getDao(String collectionName) {
		return new MongoQueryDao(db.getCollection(collectionName));
	}
}
